<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Claim extends Modules_Controller
{

	function __construct()
	{
		parent::__construct();
	}

    public function index($cid=false,$page=1)
    {
        // 栏目路径
        $vdata['cpath']= $this->mcol->get_path_more($this->cid);
        $vdata['cchildren'] = $this->mcol->get_cols($this->cid);
        $title = $this->mcol->get_one($this->cid,"title");
        $vdata['title'] = $title['title'];

        $limit = $this->page_limit;
        $this->input->get('limit',TRUE) and is_numeric($this->input->get('limit')) AND $limit = $this->input->get('limit');
        $cid=0;
        $this->db->select('*,a.stars as star');
        $this->db->from('boc_claim as a');
        $this->db->join('boc_account as b','a.uid=b.id','left');
        $where1 = array('a.cid'=>$cid,"a.ccid"=>$this->ccid,'a.is_deleted'=>0);
        if (isset($_GET['need_id'])) {
            $arr['need_id'] = $_GET['need_id'];
            $where = array_merge($arr,$where1);
        }
        if(isset($_GET['uname']) and $_GET['uname']){
            $arr['like']=array('b.uname',$_GET['uname']);
            $where = array_merge($arr,$where1);
        }
        $this->db->where($where);
        $this->db->order_by('a.created_time','desc');
        $this->db->limit($limit,$limit*($page-1));
        $vdata['list']=$this->db->get()->result_array();
        //分页
        $this->db->select('*');
        $this->db->from('boc_claim as a');
        $this->db->join('boc_account as b','a.uid=b.id','left');
        $where1 = array('a.cid'=>$cid,"a.ccid"=>$this->ccid,'a.is_deleted'=>0);
        if (isset($_GET['need_id'])) {
            $arr['need_id'] = $_GET['need_id'];
            $where = array_merge($arr,$where1);
        }
        if(isset($_GET['uname']) and $_GET['uname']){
            $arr['like']=array('b.uname',$_GET['uname']);
            $where = array_merge($arr,$where1);
        }
        $this->db->where($where);
        $all = $this->db->get()->result_array();
        $count = count($all);
        $vdata['pages'] = $this->_pages(site_url($this->class.'/index/'.$this->cid.'/'),$limit,$count,4);
        $this->_display($vdata);
    }


    protected function _pages($url,$per_page=-1,$count=0,$uri=3){
        if (!$per_page < 0) {
            $per_page = $this->page_limit;
        }
        $this->load->library('pagination');
        $this->pagination->initialize(page_config($per_page,$count,$url,$uri));
        return $this->pagination->create_links();
    }
    public function _edit_data()
    {
        $form=$this->input->post();
        $form['timeline'] = time();
        return $form;
    }
}
